package tw.twandroidproj.app.ui.resume;

import android.content.Intent;
import android.os.Bundle;
import android.os.Handler;
import android.support.v4.widget.SwipeRefreshLayout;
import android.support.v7.app.AppCompatActivity;
import android.support.v7.widget.LinearLayoutManager;
import android.support.v7.widget.OrientationHelper;
import android.support.v7.widget.RecyclerView;
import android.util.Log;
import android.view.View;
import android.widget.Button;
import android.widget.TextView;
import java.util.ArrayList;
import java.util.List;
import tw.twandroidproj.app.R;
import tw.twandroidproj.app.network.NetworkManager;

public class Resume extends AppCompatActivity implements SwipeRefreshLayout.OnRefreshListener{

    private static final int REFRESH_COMPLETE = 0X110;
    private SwipeRefreshLayout mSwipeLayout;
    private List<tw.twandroidproj.app.model.Resume> resumeDatalist=new ArrayList<tw.twandroidproj.app.model.Resume>();
    tw.twandroidproj.app.model.Resume getResumeitem2 = new tw.twandroidproj.app.model.Resume();
    tw.twandroidproj.app.model.Resume getResumeitem1 = new tw.twandroidproj.app.model.Resume();
    NetworkManager resume_networkManager;

    private Handler mHandler = new Handler()
    {
        public void handleMessage(android.os.Message msg)
        {
            switch (msg.what)
            {
                case REFRESH_COMPLETE:
                    mSwipeLayout.setRefreshing(false);
                    break;

            }
        };
    };

    @Override
    protected void onCreate(Bundle savedInstanceState) {

        super.onCreate(savedInstanceState);
        setContentView(R.layout.resume_main_test);

        TextView resume_titlebar_center = (TextView) findViewById(R.id.resume_titlebar_center);
        Button resume_titlebar_left = (Button) findViewById(R.id.resume_titlebar_left);
        Button resume_titlebar_right = (Button) findViewById(R.id.resume_titlebar_right);
        mSwipeLayout = (SwipeRefreshLayout) findViewById(R.id.resume_main_refresh);

        mSwipeLayout.setOnRefreshListener(this);
        mSwipeLayout.setColorScheme(android.R.color.holo_green_dark, android.R.color.holo_green_light,
                android.R.color.holo_orange_light, android.R.color.holo_red_light);

        getResumeitem1.setName("服务员兼职简历");
        getResumeitem1.setUpdated_at("2015/4/12");
        resumeDatalist.add(getResumeitem1);

        getResumeitem2.setName("发传单兼职简历");
        getResumeitem2.setUpdated_at("2016/5/12");
        resumeDatalist.add(getResumeitem2);

//        Log.i("到底是什么鬼之","resume_networkManager调用之前");
        resume_networkManager = NetworkManager.getInstance(this);
//        resume_networkManager.getResumeList( null, new OnResponseListener<List<tw.twandroidproj.app.model.Resume>>() {
//            @Override
//            public void onSuccess(List<tw.twandroidproj.app.model.Resume> result) {
//                Log.i("到底是什么鬼之","resume_networkManager调用onsussess");
//                resumeDatalist = result;
//
//            }
//            @Override
//            public void onFailed(ErrorModel errorModel) {
//                Log.i("到底是什么鬼之","resume_networkManager调用onfailed");
//            }
//        });

        Log.i("到底是什么鬼之","resume_networkManager调用之后");
        RecyclerView resume_recyclerView = (RecyclerView) findViewById(R.id.resume_main_list);
//        resume_recyclerView.setHasFixedSize(true);
        LinearLayoutManager recycleManager = new LinearLayoutManager(this);
        recycleManager.setOrientation(OrientationHelper.VERTICAL);
        resume_recyclerView.setLayoutManager(recycleManager);
        Log.i("到底是什么鬼之","绑定布局管理器");
        RecyclerView.Adapter resumeAdapter = new ResumeAdapter(this,resumeDatalist);
        resume_recyclerView.setAdapter(resumeAdapter);
        Log.i("到底是什么鬼之","绑定适配器");




//        TextView resume1_name=(TextView)findViewById(R.id.resume1_name);
//        TextView resume1_createtime=(TextView)findViewById(R.id.resume1_createtime);
//        TextView resume1_updatetime=(TextView)findViewById(R.id.resume1_updatetime);
//        TextView resume1_view_chinese=(TextView)findViewById(R.id.resume1_view_chinese);
//        TextView resume1_edit=(TextView)findViewById(R.id.resume1_edit);
//        TextView resume1_delete=(TextView)findViewById(R.id.resume1_delete);

          resume_titlebar_center.setText("我的简历");
          resume_titlebar_right.setText("新建");
          resume_titlebar_right.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                Intent Resume_Resume_create=new Intent(Resume.this,Resume_create.class);
                startActivity(Resume_Resume_create);
            }
          });
          resume_titlebar_left.setOnClickListener(new View.OnClickListener() {
              @Override
              public void onClick(View v) {
                  finish();
              }
          });

//        resume1_name.setText("简历1");
//        resume1_createtime.setText("创建于：");
//        resume1_updatetime.setText("更新于：");
//        resume1_view_chinese.setText("预览");
//        resume1_edit.setText("修改");
//        resume1_delete.setText("删除");

//        resume1_name.setBackgroundResource(R.drawable.resume_textview_background);
//        resume1_createtime.setBackgroundResource(R.drawable.resume_textview_background);
//        resume1_updatetime.setBackgroundResource(R.drawable.resume_textview_background);
//        resume1_view_chinese.setBackgroundResource(R.drawable.resume_textview_background);
//        resume1_edit.setBackgroundResource(R.drawable.resume_textview_background);
//        resume1_delete.setBackgroundResource(R.drawable.resume_textview_background);

//        resume1_view_chinese.setOnClickListener(new View.OnClickListener() {
//            @Override
//            public void onClick(View v) {
//                Intent main_view1 = new Intent(Resume.this, Resume_view.class);
//                startActivity(main_view1);
//            }
//        });
//
//        resume1_edit.setOnClickListener(new View.OnClickListener() {
//            @Override
//            public void onClick(View v) {
//                Intent main_edit1=new Intent(Resume.this,Resume_edit.class);
//                startActivity(main_edit1);
//            }
//        });

    }

    public void onRefresh()
    {
        // Log.e("xxx", Thread.currentThread().getName());
        // UI Thread

        mHandler.sendEmptyMessageDelayed(REFRESH_COMPLETE, 2000);

    }

}
